<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="预约管理">
        <meta name="keywords" content="预约列表">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">

        <style>
            .avatar-uploader .el-upload {
                border: 1px dashed #d9d9d9;
                border-radius: 6px;
                cursor: pointer;
                position: relative;
                overflow: hidden;
            }
            .avatar-uploader .el-upload:hover {
                border-color: #409EFF;
            }
            .avatar-uploader-icon {
                font-size: 28px;
                color: #8c939d;
                width: 178px;
                height: 178px;
                line-height: 178px;
                text-align: center;
            }
            .avatar {
                width: 178px;
                height: 178px;
                display: block;
            }
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
            .el-input__inner{
                width: 180px;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约订单管理</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <template>
                            <div class="block">
                                <el-date-picker v-model="value1"
                                        type="daterange"
                                        align="right"
                                        unlink-panels
                                        value-format="yyyy-MM-dd"
                                        range-separator="至"
                                        start-placeholder="开始日期"
                                        end-placeholder="结束日期">
                                </el-date-picker>


                                <el-select v-model="value2" placeholder="预约类型">
                                    <el-option label="微信预约" :value="1"></el-option>
                                    <el-option label="电话预约"  :value="0" ></el-option>
                                </el-select>

                                <el-select v-model="value3" placeholder="预约状态">
                                    <el-option label="未到诊" :value="1" ></el-option>
                                    <el-option label="已到诊"  :value="0"></el-option>
                                </el-select>

                                <template>
                                    <el-select v-model="value4" placeholder="套餐名称">
                                        <el-option
                                                v-for="name in setmealNames"
                                                :key="name"
                                                :label="name"
                                                :value="name">
                                        </el-option>
                                    </el-select>
                                </template>
                                <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                            </div>
                        </template>


                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                        <el-table-column prop="member.name" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="member.phoneNumber" label="手机号" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>

                        <el-table-column label="预约状态" align="center" prop="orderStatus">

                            <template slot-scope="scope">
                                <span>{{scope.row.orderStatus}}</span>

                                 <el-switch v-if="scope.row.orderStatus=='未到诊'"
                                       value="未到诊"
                                       avctie-color="#ff4949"
                                       inactive-color="#f56c6c"
                                       active-value="未到诊"
                                       inactive-value="已到诊"
                                       @change="set(scope.row)">
                                 </el-switch>

                                <el-switch v-if="scope.row.orderStatus=='已到诊'"
                                           value="已到诊"
                                           avctie-color="#ff4949"
                                           inactive-color="#f56c6c"
                                           active-value="未到诊"
                                           inactive-value="已到诊"
                                           disabled>
                                </el-switch>

                                <!--<span>
                                    <el-switch
                                            v-model="scope.row.orderStatus"
                                            avctie-color="#13ce66"
                                            inactive-color="#ff4949"
                                            active-value="未到诊"
                                            inactive-value="已到诊"
                                            @change="set(scope.row)">
                                    </el-switch>
                                </span>-->


                              <!--  <el-switch v-model="scope.row.orderStatus"
                                           avctie-color="#ff4949"
                                           inactive-color="#f56c6c"
                                           active-value="未到诊"
                                           inactive-value="已到诊"
                                           v-if="scope.row.orderStatus=='未到诊'">
                                </el-switch>

                                <el-switch v-model="scope.row.orderStatus"
                                           avctie-color="#ff4949"
                                           inactive-color="#f56c6c"
                                           active-value="未到诊"
                                           inactive-value="已到诊"
                                           @change="set(scope.row)"
                                           v-if="scope.row.orderStatus=='已到诊'">
                                </el-switch>-->

                               <!-- <span v-if="scope.row.orderStatus=='已到诊'">
                                    <el-switch
                                            v-model="value5"
                                            avctie-color="#13ce66"
                                            inactive-color="#ff4949"
                                            inactive-text=""
                                            inactive-text=""
                                            disabled
                                            @click.native="set(scope.$index, scope.row)"></el-switch>

                                </span>
                                <span v-else-if="scope.row.orderStatus=='未到诊'">
                                    <el-switch
                                            v-model="value6"
                                            avctie-color="#13ce66"
                                            inactive-color="#ff4949"
                                            inactive-text=""
                                            inactive-text=""
                                            @click.native="set(scope.$index, scope.row)"></el-switch>
                                </span>-->
                            </template>
                        </el-table-column>
                        <el-table-column prop="setmeal.name" label="套餐名称" align="center"></el-table-column>
                        <el-table-column label="预约操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleToUpdate(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagination"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>

                    <div class="add-form">
                        <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="身份证号">
                                                        <el-input v-model="formData.idCard"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="出生日期">
                                                        <el-date-picker
                                                                v-model="formData.birthday"
                                                                type="date"
                                                                value-format="yyyy-MM-dd"
                                                                placeholder="选择日期">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号">
                                                        <el-input v-model="formData.telephone"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="年龄">
                                                        <el-input v-model="formData.age"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="婚姻状态">
                                                        <el-select v-model="formData.marriyStatus">
                                                            <el-option label="未婚" value="0"></el-option>
                                                            <el-option label="已婚" value="1"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约时间">
                                                        <el-date-picker
                                                                v-model="formData.orderDate"
                                                                type="date"
                                                                value-format="yyyy-MM-dd"
                                                                placeholder="选择日期">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>套餐编号</th>
                                                    <th>套餐名称</th>
                                                    <th>套餐说明</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="c in tableData">
                                                    <td>
                                                        <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                                    </td>
                                                    <td><label :for="c.id">{{c.code}}</label></td>
                                                    <td><label :for="c.id">{{c.name}}</label></td>
                                                    <td><label :for="c.id">{{c.remark}}</label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <div class="add-form">
                        <el-dialog title="编辑预约" :visible.sync="dialogFormVisible4Edit">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="身份证号">
                                                        <el-input v-model="formData.idCard"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="出生日期">
                                                        <el-date-picker
                                                                v-model="formData.birthday"
                                                                value-format="yyyy-MM-dd"
                                                                type="date"
                                                                placeholder="选择日期">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号">
                                                        <el-input v-model="formData.telephone"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="年龄">
                                                        <el-input v-model="formData.age"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>

                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="婚姻状态">
                                                        <el-select v-model="formData.marriyStatus">
                                                            <el-option label="未婚" value="0"></el-option>
                                                            <el-option label="已婚" value="1"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约时间">
                                                        <el-date-picker
                                                                v-model="formData.orderDate"
                                                                value-format="yyyy-MM-dd"
                                                                type="date"
                                                                placeholder="选择日期">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="套餐信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>套餐名称</th>
                                                    <th>适用人群</th>
                                                    <th>套餐介绍</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="c in tableData">
                                                    <td>
                                                        <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                                    </td>
                                                    <td><label :for="c.id">{{c.name}}</label></td>
                                                    <td><label :for="c.id">
                                                        {{ c.sex == '0' ? '不限' : c.sex == '1' ? '男' : '女'}}
                                                    </label></td>

                                                    <td><label :for="c.id">{{c.remark}}</label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdt()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                value1:"",
                value2:"",
                value3:"",
                value4:"",
                value5:true,
                value6:false,
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:0,//总记录数
					  queryString:null//查询条件
				},
				dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                tableData:[],//添加表单窗口中套餐数据
                dialogFormVisible: false,//增加表单是否可见
                dialogFormVisible4Edit:false,//编辑表单是否可见
                setmealIds:[],//添加表单窗口中套餐复选框对应id
                setmealNames:[],
                rules: {//校验规则
                    /*code: [{ required: true, message: '项目编码为必填项', trigger: 'blur' }],
                    name: [{ required: true, message: '项目名称为必填项', trigger: 'blur' }]*/
                }
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();
            },
            methods: {

                set(row){

                        this.$confirm("确定改为已到诊嘛?","提示",{
                            type: 'warning'
                        }).then(()=>{
                            axios.post("/ordersetting/updateOrderStatus?id="+row.id).then((res)=>{
                                if(res.data.flag){
                                    //执行成功
                                    //弹出成功提示信息
                                    this.$message({
                                        type:'success',
                                        message:res.data.message
                                    });
                                    this.findPage();
                                }else{
                                    //执行失败
                                    this.$message.error(res.data.message);
                                }
                            }).catch((r)=>{
                                if(r == 'Error: Request failed with status code 403'){
                                    //权限不足
                                    this.$message.error('无访问权限');
                                    return;
                                }else{
                                    this.$message.error('未知错误');
                                    return;
                                }
                            });
                        }).catch(()=>{
                            this.$message({
                                type:'info',
                                message:'操作已取消'
                            })
                        });

                },

                //提交编辑数据
                handleEdt(){
                    if (this.setmealIds!=null&&this.setmealIds.length!=1){

                        this.$message.warning("预约项有且只能有一项！！！");
                        return;
                    }
                    axios.post("/ordersetting/updateOrder?setmealIds="+this.setmealIds,this.formData).then((res)=>{

                        this.dialogFormVisible4Edit=false;

                        if(res.data.flag){
                            //执行成功
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                        }else{
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).finally(() => {
                        this.findPage();
                    });
                },
                //编辑
                handleEdit() {
                    this.$refs['dataEditForm'].validate((valid)=>{
                       if(valid){

                       }else{
                           this.$message.error("表单数据校验失败!");
                           return false;
                       }
                    });
                },
                showMessage(r){
                    if(r == 'Error: Request failed with status code 403'){
                        //权限不足
                        this.$message.error('无访问权限');
                        return;
                    }else{
                        this.$message.error('未知错误');
                        return;
                    }
                },
                //添加
                handleAdd () {

                    if (this.setmealIds!=null&&this.setmealIds.length!=1){

                        this.$message.warning("预约项有且只能有一项！！！");
                        return;
                    }

                    axios.post("/ordersetting/submit?setmealIds="+this.setmealIds,this.formData).then((res)=>{

                        this.dialogFormVisible=false;
                        if(res.data.flag){
                            //执行成功
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                        }else{
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).finally(() => {
                        this.findPage();
                    });
                },
                //分页查询
                findPage() {

                    let url="/ordersetting/findOrdersPage?value1="+this.value1+"&value2="+this.value2+"&value3="+this.value3+"&value4="+this.value4;

                    var param={
                        //当前页码
                        currentPage: this.pagination.currentPage,
                        //显示数量
                        pageSize: this.pagination.pageSize,
                        //查询字段
                        queryString: this.pagination.queryString
                    };

                    axios.post(url,param).then((res)=>{
                        this.pagination.total=res.data.data.total;
                        this.dataList=res.data.data.rows;
                    });

                    this.findAllSetmealNames();
                },
                // 重置表单
                resetForm() {
                    this.formData={};
                    this.activeName = 'first';
                    this.setmealIds=[];
                },
                // 弹出添加窗口
                handleCreate() {
                    this.dialogFormVisible=true;
                    this.resetForm();
                   this.findSetmealAll()
                },
                //弹出编辑窗口
                handleToUpdate(row){
                    this.dialogFormVisible4Edit=true;
                    this.resetForm();
                    this.findSetmealAll();
                    this.findOrderById(row.id);

                },

                findOrderById(id){

                    axios.get("/ordersetting/findById/"+id).then(resp=>{
                        if (resp.data.flag){

                            this.formData=resp.data.data;
                            this.setmealIds.push(resp.data.data.setmealId);
                        }

                    });

                },

                findAllSetmealNames(){
                    axios.post("/setmeal/findAll").then((res)=>{

                        if (res.data.data!=null&&res.data.data.length>0){

                            this.setmealNames=[];

                            for (const setmeal of res.data.data) {
                                this.setmealNames.push(setmeal.name);
                            }

                        }

                    });
                },

                findSetmealAll(){
                    axios.post("/setmeal/findAll").then((res)=>{
                        this.tableData=res.data.data;
                    });
                },
                // 确定预约
                handleUpdate(row) {
                    this.$confirm("确定预约后将会以短信的方式通知客户具体体检时间，是否确定?","提示",{
                        type:'warning'
                    }).then(()=>{
                        axios.post("/localOrder/notification.do?phoneNumber="+row.phoneNumber+"&orderDate="+row.orderDate).then((res)=>{
                            if(res.data.flag){
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                                this.findPage();
                            }else{
                                // this.$message.error("执行失败");
                                this.$message({
                                    type:'fail',
                                    message:res.data.message
                                });
                            }
                        });
                    }).catch(()=>{
                        this.$message({
                            type:'info',
                            message:'操作已取消'
                        })
                    });
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage=currentPage;
                    this.findPage();
                },

                // 删除
                handleDelete(row) {
                    this.$confirm("数据删除后将无法回复，请确认是否删除?","提示",{
                        type: 'warning'
                    }).then(()=>{
                        axios.post("/ordersetting/deleteOrderById?id="+row.id+"&orderDate="+row.orderDate).then((res)=>{
                            if(res.data.flag){
                                //执行成功
                                //弹出成功提示信息
                                this.$message({
                                    type:'success',
                                    message:res.data.message
                                });
                                //重新进行分页查询
                                this.findPage();
                            }else{
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        }).catch((r)=>{
                            if(r == 'Error: Request failed with status code 403'){
                                //权限不足
                                this.$message.error('无访问权限');
                                return;
                            }else{
                                this.$message.error('未知错误');
                                return;
                            }
                        });
                    }).catch(()=>{
                        this.$message({
                            type:'info',
                            message:'操作已取消'
                        })
                    });
                }
            }
        })
    </script>
</html>